package com.ymatou.smsproxy.api.testcase;


//@TestSuite
public class Ts_SmsProxy {
	/*OrderCallService orderService;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("短信网关通道分离");
	}

	@Before
	public void caseUp() {
		orderService = new OrderCallService();
	}

	@AfterClass
	public static void tearDown() {
		// TODO no apiname 如何处理
		Logger.generateResult("");
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_001() {
		Logger.start(true,"新用户注册发送验证码成功");
		try {
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台.toString(), s.getMessagesupply(), "验证发送的渠道");
						Logger.verifyEquals(true, s.getMessage().contains("感谢您注册成为洋码头用户，本短信免费(来自洋码头ＡＰＰ)"), "验证短信内容");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_002() {
		Logger.start(true,"卖家取消发送交易通知短信");
		try {
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			// 创建订单
			Map map = orderService.createM2cOrder(user);
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 取消
			orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
			// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台通知通道.toString(), s.getMessagesupply(), "验证发送的渠道");
						Logger.verifyEquals(true, s.getMessage().contains("被卖家取消"), "验证短信内容");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_003() {
		Logger.start(true,"支付后卖家取消发送交易通知短信");
		try {
			new UserCallService();
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");	
			// 创建订单
			Map map = orderService.createM2cOrder(user);
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 取消
			orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
			// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台通知通道.toString(), s.getMessagesupply(), "验证发送的渠道");
						Logger.verifyEquals(true, s.getMessage().contains("被卖家取消，款项将原路退回到您支付的账号中。如有问题可联系卖家咨询。回复TD退订"),
								"验证短信内容");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_004() {
		Logger.start(true,"支付后买家取消发送交易通知短信");
		try {
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			// 创建订单
			Map map = orderService.createM2cOrder(user);
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 修改订单时间为2天前，让用户可以取消
			new YmtOrdersWapper().updateOrderAddtimeByOrderId(orderId, -3);
			// 用户取消
			orderService.cancelOrder(orderId, userId, CancelOrderTypeEnum.BuyerCancelOrder);
			// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台通知通道.toString(), s.getMessagesupply(), "验证发送的渠道");
						Logger.verifyEquals(true, s.getMessage().contains("取消成功，款项将原路退回到您支付的账号中。回复TD退订"), "验证短信内容");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_005() {
		Logger.start(true,"卖家已接单后取消(商家取消)发送交易通知短信");
		try {
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			// 创建订单
			Map map = orderService.createM2cOrder(user);
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
			// 卖家接单
			orderService.acceptOrder(orderId, sellerId);
			// 取消
			orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
			// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台通知通道.toString(), s.getMessagesupply(), "验证发送的渠道");
						Logger.verifyEquals(true, s.getMessage().contains("被卖家取消，款项将原路退回到您支付的账号中。如有问题可联系卖家咨询。回复TD退订"),
								"验证短信内容");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_006() {
		Logger.start(true,"交易通知短信达到上线后进去黑名单");
		try {
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			for (int i = 0; i < 4; i++) {
				// 创建订单
				Map map = orderService.createM2cOrder(user);
				int orderId = (Integer) map.get("orderId");
				int sellerId = (Integer) map.get("sellerId");
				int userId = (Integer) map.get("userId");
				int tradingId = (Integer) map.get("tradingId");
				DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
				BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
				// 取消
				orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
				// 验证验证码发送渠道(验证码通过 WM梦网平台,通知短信 通过 WM梦网平台通知通道 )
				Thread.sleep(5000);
				List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
				Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
				if (sms.size() > 0) {
					for (SmsLog s : sms) {
						if (!s.getAction().equals("Received")) {
							Logger.verifyEquals(MessageSupplyEnum.WM梦网平台通知通道.toString(), s.getMessagesupply(),
									"验证发送的渠道");
							Logger.verifyEquals(true, s.getMessage().contains("被卖家取消"), "验证短信内容");
						}
					}
				}
			}
			// 验证第5条短信进去BlankList
			// 创建订单
			Map map = orderService.createM2cOrder(user);
			int orderId = (Integer) map.get("orderId");
			int sellerId = (Integer) map.get("sellerId");
			int userId = (Integer) map.get("userId");
			int tradingId = (Integer) map.get("tradingId");
			DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
			BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
			// 取消
			orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			for (int j = 0; j < 2; j++) {
				if (!sms.get(j).getAction().equals("Received")) {
					Logger.verifyEquals(MessageSupplyEnum.NULL.toString(), sms.get(0).getMessagesupply(), "验证发送的渠道");
					Logger.verifyEquals("InBlankList", sms.get(0).getAction(), "验证超过当天短信阀值后，进去BlankList");
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SmsProxy_007() {
		Logger.start(true,"交易通知短信达到上线后验证码发送正常");
		try {
			// 注册一个新用户
			Map<String, Comparable> user = UserCallService.registerByMobile();
			String phone = (String) user.get("phone");
			Logger.comment("手机号:" + phone);
			for (int i = 0; i < 5; i++) {
				// 创建订单
				Map map = orderService.createM2cOrder(user);
				int orderId = (Integer) map.get("orderId");
				int sellerId = (Integer) map.get("sellerId");
				int userId = (Integer) map.get("userId");
				int tradingId = (Integer) map.get("tradingId");
				DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
				BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
				// 取消
				orderService.cancelOrder(orderId, sellerId, CancelOrderTypeEnum.SellerCancelOrder);
				Thread.sleep(1000);
			}
			// 验证到达阀值后，验证码短信正常发送
			SmsProxyCall call = new SmsProxyCall();
			SmsProxyBean bean = new SmsProxyBean();
			bean.setMsg("验证码[4321]");
			bean.setPhone(phone);
			call.setData(bean);
			call.callService();
			Logger.debug("发送call" + call.getEntityString());
			Logger.debug("返回call" + call.getReturnData());
			Thread.sleep(5000);
			List<SmsLog> sms = new SmsLogWapper().selectByPhone(phone);
			Logger.verifyEquals(true, sms.size() > 0, "验证发送短信");
			if (sms.size() > 0) {
				for (SmsLog s : sms) {
					if (!s.getAction().equals("Received")) {
						Logger.verifyEquals(MessageSupplyEnum.WM梦网平台.toString(), s.getMessagesupply(), "验证发送的渠道");
					}
				}
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}*/
}
